<script>
	import {mapMutations} from 'vuex';
	export default {
		watch: {
			isJimInit(n){
				if(n){
					let data = uni.getStorageSync('jimLoginInfo');
					if(data && data.username){
						this.$store.dispatch('jimLogin', data);
					}
				}
			}
		},
		computed:{
			jimLoginInfo(){
				return uni.getStorageSync('jimLoginInfo')
			},
			isJimInit(){
				return this.$store.getters.isJimInit
			}
		},
		
		onLaunch: function() {
			
			this.$store.dispatch('jimInit')
			
			
			// #ifdef APP-NVUE
			plus.screen.lockOrientation('portrait-primary');

			let appid = plus.runtime.appid;
			if (appid && appid.toLocaleLowerCase() != "hbuilder") {
				uni.request({
					url: 'https://uniapp.dcloud.io/update', //检查更新的服务器地址
					data: {
						appid: plus.runtime.appid,
						version: plus.runtime.version
					},
					success: (res) => {
						console.log('success', res);
						if (res.statusCode == 200 && res.data.isUpdate) {
							let openUrl = plus.os.name === 'iOS' ? res.data.iOS : res.data.Android;
							// 提醒用户更新
							uni.showModal({
								title: '更新提示',
								content: res.data.note ? res.data.note : '是否选择更新',
								success: (showResult) => {
									if (showResult.confirm) {
										plus.runtime.openURL(openUrl);
									}
								}
							})
						}
					}
				})
			}

			var domModule = weex.requireModule('dom');
			domModule.addRule('fontFace', {
				'fontFamily': "texticons",
				'src': "url('./static/text-icon.ttf')"
			});
			// #endif

			// 使用自定义导航栏
			uni.getSystemInfo({
				success: function(e) {
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 45;
					};
					// #endif
					// #ifdef MP-WEIXIN
					Vue.prototype.StatusBar = e.statusBarHeight;
					let custom = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
					// #endif		
					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
				}
			})
		
			// uni.clearStorageSync()
			// 判断是否登录
			// const user = uni.getStorageSync('user') || {}
			// if(!user.token) {
			// 	this.setLoginStatus(true)
			// 	uni.reLaunch({
			// 		url:'pages/login/login'
			// 	})
			// }
			
		},
		methods:{
			...mapMutations(['setLoginStatus']),
			
		},
	
		onShow: function() {
			
		},
		onHide: function() {
		}
	}
</script>

<style>
	@import "colorui/main.css";
	@import "colorui/icon.css";

	/*每个页面公共css */
	uni-page-body,body {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
	}
</style>
